// ColorComboLB.cpp : implementation file
//

#include "stdafx.h"
#include "ColorCombo.h"
#include "ColorComboLB.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CColorComboLB

CColorComboLB::CColorComboLB()
{
	m_textWidth = 25;
}

CColorComboLB::~CColorComboLB()
{
}


BEGIN_MESSAGE_MAP(CColorComboLB, CListBox)
	//{{AFX_MSG_MAP(CColorComboLB)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CColorComboLB message handlers

void CColorComboLB::DrawItem(LPDRAWITEMSTRUCT lpdis) 
{
//	return;
	CDC dc;
	CRect rcItem(lpdis->rcItem);
	COLORREF clrForeColor, clrBackColor;

	if(lpdis->itemState & ODS_SELECTED)
	{
		clrBackColor = GetSysColor(COLOR_HIGHLIGHT);
		clrForeColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
	}
	else
	{
		clrBackColor = GetSysColor(COLOR_WINDOW);
		clrForeColor = GetSysColor(COLOR_WINDOWTEXT);
	}
	dc.Attach(lpdis->hDC);
	dc.FillSolidRect(rcItem, clrBackColor);

	if(pcb->m_arr.GetSize() && (int)(lpdis->itemID) > 0)
	{
		CColorCombo::ColorComboItem item = pcb->m_arr.GetAt(lpdis->itemID);
		CRect rcColor(rcItem);

		CRect rcText(rcItem);
		rcText.right = m_textWidth;
		dc.SetTextColor(clrForeColor);
// 		CString sText;
// 		sText.Format("%02d:", item.nColorIndex);
		dc.DrawText(item.text, rcText, DT_LEFT|DT_VCENTER|DT_SINGLELINE);

		rcColor.DeflateRect(m_textWidth, 1, 1, 1);
		
		CBrush brushColor(item.color);
		CBrush *pOldBrush = dc.SelectObject(&brushColor);
		dc.Rectangle(rcColor);
		dc.SelectObject(pOldBrush);
	}

	if(lpdis->itemState & ODS_FOCUS )
	{
		dc.SetBkColor(RGB(0, 0, 0));
		dc.SetTextColor(RGB(255,255,255));
		dc.DrawFocusRect(rcItem);
	}

	dc.Detach();
}
